$(function(){
	var imgListHTML="";
	var childrens=[];
	var curChild={};
	$('.details').hide();
	/*$('body').on('click','.clk',function(){
		$('.arrow').css('display','block');
		$(this).children('img').addClass('aperture');
		$(this).siblings('li').children('img').removeClass('aperture');
		$('.details').hide();
		$('.details').show(500);
	})*/
	ym.ajax({
		url: "/userChild/getUserChild",
		success: function (data) {
		   if(data.obj){
		   	childrens=data.obj;
		   	curChild=childrens[0];
		   	for (var i = 0; i < data.obj.length; i++) {
		   		imgListHTML+="<li class='am-margin-right-xs clk' curIndex='"+data.obj[i].childId+"'><img src='"+data.obj[i].childHeadimgurl+"'></li>";
		   	}
		   	$('.child-head-list').append(imgListHTML);
		   }
		}
	});
	window.setTimeout(function(){
		$('.child-head-list li').click(function(){
			var curIndex=$(this).attr('curIndex');
			var data=new Date();
			var year=data.getFullYear();
			var month=data.getMonth()+1;
			var childForm="";
			for (var i = 0; i < childrens.length; i++) {
				if(childrens[i].childId==curIndex){
					curChild=childrens[i];
					console.log(curChild)
					var birth=childrens[i].childBirthday.split('-');
					var curYear=birth[0];
					var curMonth=birth[1];
					var newBirthYear=year-curYear;
					var newBirthMonth=month-curMonth;
					var newBirth="";
					if(newBirthYear==0){
						newBirth=newBirthMonth+"个月";
					}else{
						newBirth=newBirthYear+"岁"+newBirthMonth+"个月";
					}
					childForm+="<li class='am-margin-right-xs font14'><h4>"+childrens[i].childRealname+"</h4></li>"+
							   "<li class='am-margin-right-xs font12'><span>|</span></li>"+
							   "<li class='am-margin-right-xs font12'><span class='age'>"+newBirth+"</span></li>"
							  /* "<a class='record1 am-margin-top-sm'>"+
							   "<img src='../img/weizhi.png'>"+
							   "此处显示附近的社康  >"+
							   "</a>"*/
				}
			}
			$(this).children('img').addClass('aperture');
			$(this).siblings('li').children('img').removeClass('aperture');
			$('.information').html(childForm);
		})
	},1500)
	/*查看宝宝成长记录*/
	$('#thoughGrow').click(function(){
		sessionStorage.setItem('curChild',JSON.stringify(curChild));
		window.location.href="../html/graph.html";
		// ym.ajax({
		// 	url: "/childGrowth/getYmChildGrowth",
		// 	param:{
		// 		childId:curChild.childId
		// 	},
		// 	success: function (data) {
			   	    
		// 	   		sessionStorage.setItem('childGrowData',JSON.stringify(data.obj));
		// 	   		console.log(curChild)
		// 	   		ym.ajax({
		// 				url: "/childGrowth/getNewestYmChildGrowth",
		// 				param:{
		// 					childId:curChild.childId
		// 				},
		// 				success: function (data) {
		// 				   	sessionStorage.setItem('newChildGrowData',JSON.stringify(data.obj));
						   	
		// 				}
		// 			});
		// 	}
		// });
	})
})
